import { ValueData } from '../base-data';

/**
 * 回调函数对象
 * @param id 函数id
 * @param callback 回调函数
 */
interface IFunctionData<T> {
    id: string | number,
    callback?: { (...paras: T[]): void }
}

/**
 * 函数类型数据
 */
class FunctionData<T> extends ValueData<IFunctionData<T>>{

    protected generate(from: IFunctionData<T>): IFunctionData<T> {
        return {
            id: from.id,
            callback: from.callback
        };
    }

    protected equal(a: IFunctionData<T>, b: IFunctionData<T>): boolean {
        return a.id === b.id;
    }

    protected copy(targetContainer: IFunctionData<T>[], source: IFunctionData<T>): void {
        targetContainer[0].id = source.id;
        targetContainer[0].callback = source.callback;
    }

}


export { FunctionData };
export type { IFunctionData };